<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE HTML>
<html>
<head>
<title>注册页面</title>
<meta http-equiv=Content-Type content="text/html; charset=utf-8">
<link href="${pageContext.request.contextPath}/css/style.css"
	   type=text/css rel=stylesheet>
	<!-- Bootstrap Core CSS -->
<link href="${pageContext.request.contextPath}/css/bootstrap.min.css" rel="stylesheet" />
<script src=
       "${pageContext.request.contextPath}/js/jquery-1.11.3.min.js">
</script>

<script>
//判断是登录账号和密码是否为空
function register() {
	var username = $("#user_name").val();
	var password = $("#password").val();
	var repassword = $("#repassword").val();
	var name = $("#name").val();
	var IDcard = $("#IDcard").val();
	var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
	if (username == "" || password == "") {
		$("#message").text("账号或密码不能为空！");
		return false;
	}
	if (password != repassword) {
		$("#message").text("密码不一致，请重新输入！");
		return false;
	}
	if(name == "" || name == null){
		$("#message").text("真实姓名不能为空！");
		return false;
	}
	if(reg.test(IDcard) === false){
		$("#message").text("身份证号不正确！");
		return false;
	}
	$.post("${pageContext.request.contextPath}/createUser.action", $("#register_form").serialize(), function(data) {
		if (data == "OK") {
			alert("用户注册成功！(确认后自动跳转至登录页面)");
			window.location.replace("${pageContext.request.contextPath}/login.action");
		} else {
			alert("用户注册失败，请重试！");
			window.location.reload();
		}
	});
}
</script>
</head>
<body background="${pageContext.request.contextPath}/images/carlogin.jpg" width="100%"  >
<div ALIGN="center">
<table border="0" width="100%" cellspacing="0" cellpadding="0"
                                                           id="table1">
	<tr>
		<td height="93"></td>
		<td></td>
	</tr>
	<tr>

   <th class="login_msg" width="100%" align="center">
	 	<!-- margin:0px auto; 控制当前标签居中 -->
	 	<fieldset style="width: 100%;margin:0px auto;">
		  <legend style="text-align: center">
		     <font style="font-size:40px" face="宋体">
		          欢迎使用驾校注册系统
		     </font>
		  </legend> 
		<%-- 提交后的位置：/WEB-INF/jsp/customer.jsp--%>
		<form id="register_form" method="post" class="form-horizontal" >
                      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br /><br />

          <div class="container" style="width:340px"> 
          	<div  style="width:80%;margin:0 auto">
			 		<%-- 提示信息--%>
			 	<p style="color:red;width:100%;text-align: center" id="message">${msg}</p>
          		<span>账&nbsp;&nbsp;号：<input id="user_name" type="text" name="user_name" />
          <br /><br />
          密&nbsp;&nbsp;码：<input id="password" type="password" name="password" />
          <br /><br />
          密码确认：<input id="repassword" type="password" name="repassword" />
          <br /><br /></span>
          <span>
          	真实姓名：<input id="name" type="text" name="name" />
          </span><br /><br />
           <span>
          	身份证号：<input id="IDcard" type="text" name="IDcard" />
          </span>
          	</div>
          	<br/><br/>
          </div>
		 </form>
		 <div class="container" style="width: 340px">
			<button type="button" class="btn btn-primary" onclick="register()">注册</button>
			<a href="login.action"><button class="btn btn-danger">返回登录</button></a>
	     </div>
	 </fieldset>
	</th>
	</tr>
</table>
</div>
</body>
</html>
